package com.br.negocio.vo;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "modelo")
@SequenceGenerator(name = "modelo_seq", sequenceName = "modelo_cod_modelo_seq", allocationSize = 1)
@NamedQueries ({
	@NamedQuery(name = "loadAllModelo", query = "from ModeloVO as m order by m.codigo"),
	@NamedQuery(name = "loadAllModeloPorTipo", query = "from ModeloVO as m where m.tipoModelo = :tipo_modelo order by m.codigo"),
	@NamedQuery(name = "findModelo", query = "from ModeloVO as m where m.codigo = :codigo"),
	@NamedQuery(name = "findDuplicatedModelo", query = "from ModeloVO as m where m.descricao = :descricao and m.marcaVO.codigo = :cod_marca and m.tipoModelo = :cod_tipo_modelo and m.codigo != :codigo")
})
public class ModeloVO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "cod_modelo")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "modelo_seq")
	private int codigo;
	
	@Column(name = "descricao", nullable = false, length = 50)
	private String descricao;
	
	@Column(name = "cod_tipo_modelo", nullable = false)
	private int tipoModelo;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "cod_marca", nullable = false)
	@Fetch(FetchMode.JOIN)
	private MarcaVO marcaVO;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_criacao", nullable = false)
	private Date dataCriacao;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_alteracao", nullable = false)
	private Date dataAlteracao;
	
	public ModeloVO() {

	}

	public int getCodigo() {
		return this.codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public String getDescricao() {
		return this.descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	
	public int getTipoModelo() {
		return tipoModelo;
	}

	public void setTipoModelo(int tipoModelo) {
		this.tipoModelo = tipoModelo;
	}

	public MarcaVO getMarcaVO() {
		return this.marcaVO;
	}

	public void setMarcaVO(MarcaVO marcaVO) {
		this.marcaVO = marcaVO;
	}
	
	public Date getDataCriacao() {
		return this.dataCriacao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public Date getDataAlteracao() {
		return this.dataAlteracao;
	}

	public void setDataAlteracao(Date dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}
		
}